package com.zh.blog.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc;

import java.util.Collections;

/**
 * knife4j配置类
 * 这是一个对swagger接口文档进行增强的工具
 * @author ZhengHao
 * Created At 2022/8/1.
 **/
@Configuration
@EnableSwagger2WebMvc
public class Knife4jConfig {
    @Bean
    public Docket createRestApi(){
        return new Docket(DocumentationType.SWAGGER_2)
                .produces(Collections.singleton("https"))
                .host("http://www.zh.com")
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.zh.blog.controller"))
                .paths(PathSelectors.any())
                .build();
    }

    private ApiInfo apiInfo(){
        return new ApiInfoBuilder()
                .title("博客API文档")
                .description("springboot+vue的博客项目")
                .contact(new Contact("紫萼", "https://gitee.com/zhenghaodimple", "1775825464@qq.com"))
                .termsOfServiceUrl("https://www.zh.com/api")
                .version("1.0")
                .build();
    }
}